package com.westos.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Description:
 * @Author: 大强
 * @CreateTime: 2020/1/12
 * @Company: 西部开源教育科技有限公司
 */
public abstract class MultiController implements Controller {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        //查找方法
        String method = req.getParameter("method");
        //执行方法
        doExecute(method,req,resp);
    }

    protected  void doExecute(String method,HttpServletRequest req, HttpServletResponse resp){
        Method m = null;
        try {
            m = this.getClass().getMethod(method, HttpServletRequest.class , HttpServletResponse.class);
            m.invoke(this,req,resp);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    };
}
